﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using Controller;

namespace Facade.Validator
{
    public class UoMDetailValidator
    {
        public string ValidateOnSave(UoMDetail Details)
        {
            string msg = "OK";
            if (Details.Description.Trim().Length <= 0)
                msg = "Please Enter UoM Detail Description";
            if (Details.ListValue.Trim().Length <= 0)
                msg = "Please Enter UoM Detail List Value";
            else
            {
                switch (Details.UoM.Format)
                {
                    case (UoMFormat.Numeric):
                        float number;
                        if (!float.TryParse(Details.ListValue, out number))
                            msg = "Mismatched list value and UoM format";
                        break;
                    default: break;
                }
            }
            if (Details.UoMType.Trim().Length <= 0)
                msg = "Please Enter UoM Detail UoMType";
            if (Details.UoM == null)
                msg = "Please Enter UoM";

            return msg;
        }

        public string ValidateOnUpdate(UoMDetail Details)
        {
            string msg = "OK";
            if (Details.Description.Trim().Length <= 0)
                msg = "Please Enter UoM Detail Description";
            if (Details.ListValue.Trim().Length <= 0)
                msg = "Please Enter UoM Detail List Value";
            else
            {
                switch (Details.UoM.Format)
                {
                    case (UoMFormat.Numeric):
                        int number;
                        if (!Int32.TryParse(Details.ListValue, out number))
                            msg = "Mismatched list value and UoM format";
                        break;
                    default: break;
                }
            }
            if (Details.UoMType.Trim().Length <= 0)
                msg = "Please Enter UoM Detail UoMType";
            if (Details.UoM == null)
                msg = "Please Enter UoM";

            return msg;
        }
    }
}